
Imports Microsoft.Ink

Public Class ShareInk
    Inherits System.Windows.Forms.Form

    ' capture ink locally
    Public WithEvents CaptureInk As New InkCollector(Me.handle)
    Public DrawingInk As New Ink()

    ' connection to remote tablet
    Private InkConnect As New InkConnection(Me)

#Region " Windows Form Designer generated code "
    Public Sub New()
        InitializeComponent()
    End Sub

    Public Shared Sub Main()
        Application.Run(New shareINK())
    End Sub

    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents IncomingData As System.Windows.Forms.Timer
    Friend WithEvents PanelControl As System.Windows.Forms.Panel
    Friend WithEvents ButtonConnect As System.Windows.Forms.Button
    Friend WithEvents TextRemote As System.Windows.Forms.TextBox
    Friend WithEvents LabelRemote As System.Windows.Forms.Label
    Friend WithEvents ButtonListen As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.IncomingData = New System.Windows.Forms.Timer(Me.components)
        Me.PanelControl = New System.Windows.Forms.Panel()
        Me.LabelRemote = New System.Windows.Forms.Label()
        Me.ButtonListen = New System.Windows.Forms.Button()
        Me.ButtonConnect = New System.Windows.Forms.Button()
        Me.TextRemote = New System.Windows.Forms.TextBox()
        Me.PanelControl.SuspendLayout()
        Me.SuspendLayout()
        '
        'IncomingData
        '
        Me.IncomingData.Enabled = True
        '
        'PanelControl
        '
        Me.PanelControl.BackColor = System.Drawing.SystemColors.ControlLight
        Me.PanelControl.Controls.AddRange(New System.Windows.Forms.Control() {Me.LabelRemote, Me.ButtonListen, Me.ButtonConnect, Me.TextRemote})
        Me.PanelControl.Dock = System.Windows.Forms.DockStyle.Top
        Me.PanelControl.Name = "PanelControl"
        Me.PanelControl.Size = New System.Drawing.Size(592, 40)
        Me.PanelControl.TabIndex = 3
        '
        'LabelRemote
        '
        Me.LabelRemote.Location = New System.Drawing.Point(10, 11)
        Me.LabelRemote.Name = "LabelRemote"
        Me.LabelRemote.Size = New System.Drawing.Size(90, 20)
        Me.LabelRemote.TabIndex = 6
        Me.LabelRemote.Text = "Remote Tablet:"
        Me.LabelRemote.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'ButtonListen
        '
        Me.ButtonListen.Location = New System.Drawing.Point(320, 10)
        Me.ButtonListen.Name = "ButtonListen"
        Me.ButtonListen.Size = New System.Drawing.Size(80, 20)
        Me.ButtonListen.TabIndex = 5
        Me.ButtonListen.Text = "Listen"
        '
        'ButtonConnect
        '
        Me.ButtonConnect.Location = New System.Drawing.Point(230, 10)
        Me.ButtonConnect.Name = "ButtonConnect"
        Me.ButtonConnect.Size = New System.Drawing.Size(80, 20)
        Me.ButtonConnect.TabIndex = 4
        Me.ButtonConnect.Text = "Connect"
        '
        'TextRemote
        '
        Me.TextRemote.Location = New System.Drawing.Point(100, 10)
        Me.TextRemote.Name = "TextRemote"
        Me.TextRemote.Size = New System.Drawing.Size(120, 21)
        Me.TextRemote.TabIndex = 3
        Me.TextRemote.Text = "mwa17727"
        '
        'ShareInk
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.BackColor = System.Drawing.SystemColors.Window
        Me.ClientSize = New System.Drawing.Size(592, 383)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PanelControl})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "ShareInk"
        Me.Text = "ShareInk -- written by Jeffrey Sharkey"
        Me.PanelControl.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub FormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' set default properties
        Me.CaptureInk.DefaultDrawingAttributes.Color = Color.Green
        Me.CaptureInk.DefaultDrawingAttributes.Width = 100
        Me.CaptureInk.Enabled = True

        ' let user know how to use
        MsgBox("ShareInk version 0.01 -- written by Jeffrey Sharkey" + vbCrLf + _
            "Distributed as freeware as of May 7, 2003." + vbCrLf + _
            vbCrLf + _
            "To use, get two Tablet PC's on a wireless network.  Know the name of one of the" + vbCrLf + _
            "tablets, or at least the IP address.  Have the known tablet ""Listen"" while the" + vbCrLf + _
            "other tablet connects to it.  After they connect, local strokes are appear green" + vbCrLf + _
            "while remote strokes appear red.  To disconnect, close both programs." + vbCrLf + _
            vbCrLf + _
            "Great for long meetings!")
    End Sub

    Private Sub captureInkStroke(ByVal sender As Object, ByVal e As Microsoft.Ink.InkCollectorStrokeEventArgs) Handles CaptureInk.Stroke
        ' send the new stroke to partner
        Me.InkConnect.SendStroke(e.Stroke)
    End Sub

    Private Sub IncomingDataTick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IncomingData.Tick
        ' check for incoming stroke
        Dim ThisStroke As Stroke = Me.InkConnect.ReceiveStroke()

        ' if it exists then draw it on the canvas
        If Not ThisStroke Is Nothing Then
            ThisStroke.DrawingAttributes.Color = Color.Red
            Me.CaptureInk.Renderer.Draw(Me.CreateGraphics, ThisStroke)
            Me.CaptureInk.DefaultDrawingAttributes.Color = Color.Green
        End If
    End Sub

    Private Sub ButtonConnectClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click
        Me.InkConnect.Connect(Me.TextRemote.Text)
    End Sub

    Private Sub ButtonListen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonListen.Click
        Me.InkConnect.Listen()
    End Sub
End Class
